<!--
 * @description  : 案件详情信息-案件当事人/同案人信息
 * @descriptionDetail: 案件详情信息-案件当事人/同案人信息
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-07-12 21:31:06
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar :is-white="false" :title="navTitle" :custom-back="goBack" style="z-index: 99999">
    </theme-navbar>
    <!-- #endif -->
    <view class="content">
      <view class="party-info-content">
        <view style="width: calc(100% - 30px);">
          <form-section title="涉案人类别"></form-section>
        </view>
        <view class="party-info-box">
          <u-form-item
            label-width="auto"
            label-position="top"
            label="涉案人类别"
            :required="true"
          >
            <view style="width: 100%;display: flex;flex-direction: row;justify-content: space-between;">
              <u-radio-group v-model="partyType" @change="radioGroupChange">
                <u-radio :name="item.value" v-for="item in partyTypeList" :key="item.key">
                  {{ item.name }}
                </u-radio>
              </u-radio-group>
            </view>
          </u-form-item>
          <view style="margin: 0px -16px;">
            <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
          </view>
          <view style="width: calc(100% - 30px);">
            <form-section title="头像信息"></form-section>
          </view>
          <u-form-item label-width="auto" label-position="left" label="上传头像">
            <view style="width: 100%;display: flex;flex-direction: row;justify-content: flex-end;">
              <m-upload
                index="1"
                :multiple="false"
                :maxCount="1"
                :width="150"
                :height="150"
                :fileList="personImagesList"
                :uploadParam="{'fiGroupCode':$FILE_GROUP_TYPE.c_party_image, 'bizId': caseUuid}"
                @on-list-change="getImgs"
              ></m-upload>
            </view>
          </u-form-item>
          <!-- 自然人的form -->
          <u-form
            :model="dataFormPerson"
            label-width="auto"
            label-position="top"
            :errorType="['border-bottom','message',]"
            v-show="PARTY_TYPE_CODE.personal == partyType"
            :rules="personRules"
            ref="uFormPerson"
          >
            <view style="margin: 0px -16px;">
              <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
            </view>
            <view style="width: calc(100% - 30px);">
              <form-section title="涉案信息"></form-section>
            </view>
            <u-form-item prop="roleOfCaseStr" rightIcon="arrow-right" :required="true" label="涉案关系">
              <dic-input
                :needValid="true"
                :keyWord="$u.dic.DIC_KEYS.ROLE_OF_CASE"
                :dicCode="dataFormPerson.roleOfCase"
                :border="false"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.ROLE_OF_CASE)"
                placeholder="请选择"
                v-model="dataFormPerson.roleOfCaseStr"
                @changeInputModelData="(name)=>{$set(dataFormPerson, 'roleOfCaseStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.ROLE_OF_CASE,dataFormPerson.roleOfCase)"
              />
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="参与角色">
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.C_PARTYINFO_TYPE"
                :dicCode="dataFormPerson.partakeRole"
                :border="false"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.C_PARTYINFO_TYPE)"
                placeholder="请选择"
                v-model="dataFormPerson.partakeRoleStr"
                @changeInputModelData="(name)=>{$set(dataFormPerson, 'partakeRoleStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.C_PARTYINFO_TYPE,dataFormPerson.partakeRole)"
              />
            </u-form-item>
            <view style="margin: 0px -16px;">
              <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
            </view>
            <view style="width: calc(100% - 30px);">
              <form-section title="身份信息"></form-section>
            </view>
            <u-form-item
              label="涉案人"
              :required="true"
              prop="partyName"
            >
              <auto-input
                absIndex="4"
                :searchData="searchEnterPerson"
                absClass="caseFromClass"
                placeholder="涉案人模糊查询"
                v-model="dataFormPerson.partyName"
                @choiceAutoItem="choiceAutoItem"
                style="width:100%"
              >
              </auto-input>
            </u-form-item>
            <u-form-item
              :required="true"
              prop="partySex"
              label="性别"
              rightIcon="arrow-right"
            >
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.BSC_GENDDER"
                :dicCode="dataFormPerson.partySex"
                :border="false"
                type="text"
                :needValid="true"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.BSC_GENDDER)"
                placeholder="请选择"
                v-model="dataFormPerson.partySexStr"
                @changeInputModelData="(name)=>{$set(dataFormPerson, 'partySexStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.BSC_GENDDER,dataFormPerson.partySex)"
              />
            </u-form-item>
            <u-form-item rightIcon="arrow-right" :required="true" label="民族" prop="nation">
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.NATION_LIST"
                :dicCode="dataFormPerson.nation"
                :border="false"
                :needValid="true"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.NATION_LIST)"
                placeholder="请选择"
                v-model="dataFormPerson.nationStr"
                @changeInputModelData="(name)=>{$set(dataFormPerson, 'nationStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.NATION_LIST,dataFormPerson.nation)"
              />
            </u-form-item>

            <u-form-item label="曾用名">
              <u-input placeholder="请输入曾用名" v-model="dataFormPerson.alias"></u-input>
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="证件类型" prop="idCardType">
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.IDCARD_TYPE"
                :dicCode="dataFormPerson.idCardType"
                :border="false"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.IDCARD_TYPE)"
                placeholder="请选择"
                v-model="dataFormPerson.idCardTypeStr"
                @changeInputModelData="(name)=>{$set(dataFormPerson, 'idCardTypeStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.IDCARD_TYPE,dataFormPerson.idCardType)"
              />
            </u-form-item>

            <u-form-item
              label="证件号码"
              prop="idCard"
              class="idCardClass"
              :required="!$u.test.isEmpty(dataFormPerson.idCardTypeStr)"
            >
              <auto-input
                absIndex="1"
                :replaceSearchVal="false"
                tplClass="width100"
                :searchData="searchData"
                absClass="idCardClass"
                placeholder="请输入证件号码"
                v-model="dataFormPerson.idCard"
                @choiceAutoItem="choiceAutoItem"
              >
              </auto-input>
            </u-form-item>
            <u-form-item label="证件地址">
              <u-input type="textarea" placeholder="请输入证件地址" v-model="dataFormPerson.idCardAddr"></u-input>
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="出生日期">
              <u-input
                :disabled="true"
                type="text"
								:custom-style="pointerStyle"
                placeholder="请选择出生日期"
                v-model="dataFormPerson.birthday"
                @click="dateShow = true"
              ></u-input>
            </u-form-item>
            <u-form-item label="年龄">
              <u-input type="digit" placeholder="请输入年龄" v-model="dataFormPerson.age"></u-input>
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="籍贯">
              <u-input
                type="text"
                placeholder="请选择"
                :disabled="true"
								:custom-style="pointerStyle"
                v-model="dataFormPerson.nativeAreaStr"
                @click="showArea(1)"
              ></u-input>
            </u-form-item>
            <u-form-item label="现居地">
              <u-input type="textarea" placeholder="请输入" v-model="dataFormPerson.busiAddr"></u-input>
            </u-form-item>
            <u-form-item label="职业">
              <u-input placeholder="请输入职业" v-model="dataFormPerson.duty"></u-input>
            </u-form-item>
            <view style="margin: 0px -16px;">
              <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
            </view>
            <view style="width: calc(100% - 30px);">
              <form-section title="经营信息"></form-section>
            </view>
            <u-form-item label="字号名称" prop="companyName">
              <u-input placeholder="请输入字号名称" v-model="dataFormPerson.companyName" />
            </u-form-item>
            <u-form-item label="统一社会信用代码(营业执照)">
              <u-input type="text" placeholder="请输入统一社会信用代码(营业执照)" v-model="dataFormPerson.busiLiceNo">
              </u-input>
            </u-form-item>
            <u-form-item
              label="经营地址"
              :required="true"
              prop="personalBusiAddr"
            >
              <u-input type="text" placeholder="请输入经营地址" v-model="dataFormPerson.personalBusiAddr" />
            </u-form-item>
            <u-form-item label="经营地址邮编">
              <u-input type="text" placeholder="请输入经营地址邮编" v-model="dataFormPerson.partyPostcode" />
            </u-form-item>
            <u-form-item label="工作单位">
              <u-input type="text" placeholder="请输入工作单位" v-model="dataFormPerson.company"></u-input>
            </u-form-item>
            <u-form-item label="联系电话" :required="true" prop="phone">
              <u-input placeholder="请输入联系电话" type="number" v-model="dataFormPerson.phone" />
            </u-form-item>
          </u-form>
          <!-- 法人的form -->
          <u-form
            :model="dataFormBusOther"
            label-width="auto"
            label-position="top"
            :errorType="['border-bottom','message',]"
            v-show="PARTY_TYPE_CODE.personal != partyType"
            :rules="busOtherRules"
            ref="uFormBusOther"
          >
            <view style="margin: 0px -16px;">
              <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
            </view>
            <view style="width: calc(100% - 30px);">
              <form-section title="企业信息"></form-section>
            </view>
            <u-form-item prop="roleOfCaseStr" rightIcon="arrow-right" :required="true" label="涉案关系">
              <dic-input
                :needValid="true"
                :keyWord="$u.dic.DIC_KEYS.ROLE_OF_CASE"
                :dicCode="dataFormBusOther.roleOfCase"
                :border="false"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.ROLE_OF_CASE)"
                placeholder="请选择"
                v-model="dataFormBusOther.roleOfCaseStr"
                @changeInputModelData="(name)=>{$set(dataFormBusOther, 'roleOfCaseStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.ROLE_OF_CASE,dataFormBusOther.roleOfCase)"
              />
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="参与角色">
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.C_PARTYINFO_TYPE"
                :dicCode="dataFormBusOther.partakeRole"
                :border="false"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.C_PARTYINFO_TYPE)"
                placeholder="请选择"
                v-model="dataFormBusOther.partakeRoleStr"
                @changeInputModelData="(name)=>{$set(dataFormBusOther, 'partakeRoleStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.C_PARTYINFO_TYPE,dataFormBusOther.partakeRole)"
              />
            </u-form-item>
            <u-form-item
              label="涉案企业"
              :required="true"
              prop="partyName"
            >
              <!-- <u-input placeholder="请输入" v-model="dataFormBusOther.partyName" /> -->
              <auto-input
                absIndex="3"
                :searchData="searchEnterprise"
                absClass="caseFromClass"
                placeholder="涉案企业模糊查询"
                v-model="dataFormBusOther.partyName"
                @choiceAutoItem="choiceAutoItem"
                style="width:100%"
              >
              </auto-input>
            </u-form-item>
            <u-form-item label="统一社会信用代码(营业执照)" :required="true" prop="busiLiceNo">
              <u-input type="text" placeholder="请输入统一社会信用代码(营业执照)" v-model="dataFormBusOther.busiLiceNo">
              </u-input>
              <u-icon v-if="dataFormBusOther.busiLiceNo" name="integral" :color="$theme.u_type_primary" size="50" @click="infoSelect()"></u-icon>
            </u-form-item>
            <u-form-item
              label="经营地址"
              :required="true"
              prop="busiAddr"
            >
              <u-input type="text" placeholder="请输入经营地址" v-model="dataFormBusOther.busiAddr" />
            </u-form-item>
            <u-form-item label="联系电话" :required="true" prop="phone">
              <u-input placeholder="请输入联系电话" type="number" v-model="dataFormBusOther.phone" />
            </u-form-item>
            <view style="margin: 0px -16px;">
              <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
            </view>
            <view style="width: calc(100% - 30px);">
              <form-section title="法定代表人(负责人)信息"></form-section>
            </view>
            <u-form-item
              label="法定代表人(负责人)"
              prop="picPerson"
              :required="true"
            >
              <u-input placeholder="请输入" v-model="dataFormBusOther.picPerson" />
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="证件类型" prop="idCardType">
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.IDCARD_TYPE"
                :dicCode="dataFormBusOther.idCardType"
                :border="false"
                type="text"
                :disabled="true"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.IDCARD_TYPE)"
                placeholder="请选择"
                v-model="dataFormBusOther.idCardTypeStr"
                @changeInputModelData="(name)=>{$set(dataFormBusOther, 'idCardTypeStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.IDCARD_TYPE,dataFormBusOther.idCardType)"
              />
            </u-form-item>
            <u-form-item
              label="证件号码"
              prop="picIdCard"
              class="idCardClass"
              :required="!$u.test.isEmpty(dataFormBusOther.idCardTypeStr)"
            >
              <auto-input
                absIndex="2"
                :replaceSearchVal="false"
                tplClass="width100"
                :searchData="searchData"
                absClass="idCardClass"
                placeholder="请输入证件号码"
                v-model="dataFormBusOther.picIdCard"
                @choiceAutoItem="choiceAutoItem"
              >
              </auto-input>
            </u-form-item>
            <u-form-item
              label="证件地址"
            >
              <u-input placeholder="请输入" v-model="dataFormBusOther.idCardAddr" />
            </u-form-item>
            <u-form-item
              :required="true"
              prop="partySex"
              label="性别"
              rightIcon="arrow-right"
            >
              <dic-input
                :needValid="true"
                :keyWord="$u.dic.DIC_KEYS.BSC_GENDDER"
                :dicCode="dataFormBusOther.partySex"
                :border="false"
                type="text"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.BSC_GENDDER)"
                placeholder="请选择"
                v-model="dataFormBusOther.partySexStr"
                @changeInputModelData="(name)=>{$set(dataFormBusOther, 'partySexStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.BSC_GENDDER,dataFormBusOther.partySex)"
              />
            </u-form-item>
            <u-form-item rightIcon="arrow-right" :required="true" label="民族" prop="nation">
              <dic-input
                :keyWord="$u.dic.DIC_KEYS.NATION_LIST"
                :dicCode="dataFormBusOther.nation"
                :border="false"
                :needValid="true"
                type="text"
                :select-open="dicSelectOpen($u.dic.DIC_KEYS.NATION_LIST)"
                placeholder="请选择"
                v-model="dataFormBusOther.nationStr"
                @changeInputModelData="(name)=>{$set(dataFormBusOther, 'nationStr', name)}"
                @click="showDic($u.dic.DIC_KEYS.NATION_LIST,dataFormBusOther.nation)"
              />
            </u-form-item>
            <u-form-item rightIcon="arrow-right" label="籍贯">
              <u-input
                type="text"
                placeholder="请选择"
                :disabled="true"
								:custom-style="pointerStyle"
                v-model="dataFormBusOther.nativeAreaStr"
                @click="showArea(1)"
              ></u-input>
            </u-form-item>
            <u-form-item label="职务">
              <u-input placeholder="请输入职务" type="text" v-model="dataFormBusOther.picPost" />
            </u-form-item>
            <u-form-item label="电话">
              <u-input placeholder="请输入电话" type="number" v-model="dataFormBusOther.picPhone" />
            </u-form-item>
            <u-form-item label="年龄">
              <u-input type="digit" placeholder="请输入年龄" v-model="dataFormBusOther.age"></u-input>
            </u-form-item>
          </u-form>
        </view>
      </view>
      <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
      <view class="ext-lay">
        <view class="ext-lay-header">
          <view style="width: calc(100% - 30px);">
            <form-section title="扩展信息"></form-section>
          </view>
          <view>
            <u-button type="primary" plain size="mini" @click="addExtInfo">
              新增
            </u-button>
          </view>
        </view>
        <view>
          <u-swipe-action
            :show="item.show"
            :index="index"
            :options="newOptions"
            v-for="(item,index) in partyExList"
            :key="item.id"
            @click="extClick"
            @open="extOpen"
          >
            <view class="ext-lay-content">
              <view class="ext-lay-content-title">
                信息分类: {{ getDicName(item.infoType) }}
              </view>
              <view class="ext-lay-content-sub">
                信息项: {{ item.infoItem }}
              </view>
              <view class="ext-lay-content-sub">
                信息内容: {{ item.infoContent }}
              </view>
            </view>
          </u-swipe-action>
        </view>
      </view>
      <view class="space-content"></view>
      <view class="submit-btns btn-other-cls">
        <u-button class="u-btn" type="primary" @click="save">
          保存
        </u-button>
      </view>
    </view>
    <!-- 日期控件 -->
    <u-picker mode="time" :params="paramsDate" v-model="dateShow" @confirm="changeDateCb">
    </u-picker>
    <dic-choice
      :keyWord="dicKeyWords"
      :currentSelect="dicCurrentSelect"
      v-model="dicShow"
      @confirm="selectDicConfirm"
    ></dic-choice>
    <!-- 扩展信息 -->
    <u-popup mode="bottom" height="50%" v-model="extInfoShow">
      <ext-info-item :oldData="choiceExtItem" @confirm="confirmExtItem"></ext-info-item>
    </u-popup>
    <!-- 行政区划选择 -->
    <u-popup mode="bottom" height="80%" v-model="areaShow">
      <area-select @choose="nativeNameSelectShowComfir"></area-select>
    </u-popup>
  </view>
</template>

<script>
import DicChoice from "@/components/dic_choice.vue";
import DicInput from "@/components/dic_input.vue";
import mUpload from "@/components/m-upload.vue";
import extInfoItem from "../components/extInfoItem.vue";
import AutoInput from "@/components/autoInput.vue";
import caseService from "@/service/case/case.service";
import commonService from "@/service/common/common.service";
import areaSelect from "@/components/area-select.vue";
import FormSection from "@/components/form-section.vue";
import {
  PARTY_TYPE_CODE,
  C_INFO_TYPE,
  IDCARD_TYPE_CODE,
  GENDER_TYPE,
} from "@/service/case/mapping/index.js";
import {
  v4 as uuidv4,
} from 'uuid';
import {getGenderByIdNumber,} from "@/common/util"
export default {
  components: {
    "dic-choice": DicChoice,
    "dic-input": DicInput,
    extInfoItem,
    AutoInput,
    mUpload,
    areaSelect,
    FormSection,
  },
  data() {
    return {
      IDCARD_TYPE_CODE,
      PARTY_TYPE_CODE,
      caseUuid: "",
      partyUuid:"",
      dateShow: false,
      areaShow : false,
      areaType: 1, // 1 籍贯  2 经营地址
      personImagesList: [],
      partyType: PARTY_TYPE_CODE.personal,
      paramsDate: {
        year: true,
        month: true,
        day: true,
        hour: false,
        minute: false,
        second: false,
        timestamp: true,
      },
      extInfoShow: false,
      choiceExtItem: undefined,
      dataFormPerson:{
        roleOfCase: '01',
        nativeAreaStr:"",
        busiAreaStr:"",
      },
      dataFormBusOther:{},
      partyTypeList: [{
        name: "自然人",
        value: PARTY_TYPE_CODE.personal,
        key: "gongmin",
      },
      {
        name: "法人",
        value: PARTY_TYPE_CODE.business,
        key: "faren",
      },
      {
        name: "其他组织",
        value: PARTY_TYPE_CODE.other,
        key: "other",
      },
      ],
      newOptions: [{
        text: '编辑',
        style: {
          backgroundColor: '#007aff',
        },
      },
      {
        text: '删除',
        style: {
          backgroundColor: '#dd524d',
        },
      },
      ],
      personRules: {
        roleOfCaseStr: [{
          required: true,
          message: '请选择涉案关系',
          trigger: ['change', 'blur',],
        },],
        partyName: [{
          required: true,
          message: '请输入涉案人',
          trigger: ['change', 'blur',],
        },],
        partySex: [{
          required: true,
          message: '请选择性别',
          trigger: ['change', 'blur',],
        },],
        nation: [{
          required: true,
          message: '请选择民族',
          trigger: ['change', 'blur',],
        },],
        idCard: [{
          validator: (rule, value, callback) => {
            if(this.$u.test.isEmpty(this.dataFormPerson.idCardTypeStr)){
              return true;
            }else{
              return !this.$u.test.isEmpty(value);
            }
          },
          message: '请输入证件号码',
          trigger: ['change', 'blur',],
        },{
          validator: (rule, value, callback) => {
            if (this.dataFormPerson.idCardType == IDCARD_TYPE_CODE.IDENTIFICATION || this.dataFormPerson.idCardType == IDCARD_TYPE_CODE.TEMID) {
              return this.$u.test.idCard(value);
            } else {
              return true;
            }
          },
          message: '请输入正确证件号码',
          trigger: ['change', 'blur',],
        },],
        phone:[{
          required: true,
          message: '请输入联系电话',
          trigger: ['change', 'blur',],
        },
        {
          validator: (rule, value) => {
            return !value || this.$u.test.mobile(value);
          },
          message: '手机号码不正确',
          trigger: ['change','blur',],
        },
        ],
        personalBusiAddr:[{
          required: true,
          message: '请输入经营地址',
          trigger: ['change', 'blur',],
        },],
      },
      busOtherRules: {
        roleOfCaseStr: [{
          required: true,
          message: '请选择涉案关系',
          trigger: ['change', 'blur',],
        },],
        partyName: [{
          required: true,
          message: '请输入涉案企业',
          trigger: ['change', 'blur',],
        },],
        picIdCard: [{
          validator: (rule, value, callback) => {
            if (this.partyType == PARTY_TYPE_CODE.personal) return true;
            if(this.$u.test.isEmpty(this.dataForm.idCardTypeStr)){
              return true;
            }else{
              return !this.$u.test.isEmpty(value);
            }
          },
          message: '请输入证件号码',
          trigger: ['change', 'blur',],
        },
        {
          validator: (rule, value, callback) => {
            if (this.partyType == PARTY_TYPE_CODE.personal) return true;
            if (this.dataForm.idCardType == IDCARD_TYPE_CODE.IDENTIFICATION || this.dataForm.idCardType == IDCARD_TYPE_CODE.TEMID) {
              return this.$u.test.idCard(value);
            } else {
              return true;
            }
          },
          message: '请输入正确的证件号码',
          trigger: ['change', 'blur',],
        },
        ],
        partySex: [{
          required: true,
          message: '请选择性别',
          trigger: ['change', 'blur',],
        },],
        nation: [{
          required: true,
          message: '请选择民族',
          trigger: ['change', 'blur',],
        },],
        phone:[{
          required: true,
          message: '请输入联系电话',
          trigger: ['change', 'blur',],
        },
        {
          validator: (rule, value) => {
            return !value || this.$u.test.mobile(value);
          },
          message: '手机号码不正确',
          trigger: ['change','blur',],
        },
        ],
        picPerson:[{
          required: true,
          message: '请输入法定代表人(负责人)',
          trigger: ['change', 'blur',],
        },],
        busiLiceNo:[{
          required: true,
          message: '请输入统一社会信用代码(营业执照)',
          trigger: ['change', 'blur',],
        },],
        busiAddr:[{
          required: true,
          message: '请输入经营地址',
          trigger: ['change', 'blur',],
        },],
      },
      pickerShow: false, // 地址选择
      dicShow: false, // dic_select 是否显示
      dicKeyWords: "", // dic 关键字
      dicCurrentSelect: "", // dic 当前选择项
      partyExList: [], // 扩展信息
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx start
			pointerStyle: {
			  marginRight: "5px",
				pointerEvents: "none !important"
			},
			// h5端部分浏览器input设置disabled后点击事件失效 2023-10-27 fsx end
    }
  },
  onReady() {
    this.$refs.uFormPerson.setRules(this.personRules);
    this.$refs.uFormBusOther.setRules(this.busOtherRules);
  },
  // 加载初始周期方法
  onLoad(opt) {
    let param = this.getRouteParam();
    this.caseUuid = opt.caseUuid;
    if (param) {
      this.partyType = param.partyType;
      this.partyUuid = param.partyUuid;
      this.objMerge(this.dataForm, param);
      if(!this.$u.test.isEmpty(this.dataForm.nativeProvCode) && !this.$modal.isMuniCity(this.dataForm.nativeProvCode)){
        this.dataForm.nativeAreaStr = commonService.getPersonLocal(this.dataForm.nativeProvCode, true).areaName || "";
      }
      if(!this.$u.test.isEmpty(this.dataForm.nativeCityCode)){
        this.dataForm.nativeAreaStr += commonService.getPersonLocal(this.dataForm.nativeCityCode, true).areaName || "";
      }
      if(!this.$u.test.isEmpty(this.dataForm.nativeCountyCode)){
        this.dataForm.nativeAreaStr += commonService.getPersonLocal(this.dataForm.nativeCountyCode, true).areaName || "";
      }
      if(!this.$u.test.isEmpty(this.dataForm.busiProvCode) && !this.$modal.isMuniCity(this.dataForm.busiProvCode)){
        this.dataForm.busiAreaStr = commonService.getPersonLocal(this.dataForm.busiProvCode, true).areaName || "";
      }
      if(!this.$u.test.isEmpty(this.dataForm.busiCityCode)){
        this.dataForm.busiAreaStr += commonService.getPersonLocal(this.dataForm.busiCityCode, true).areaName || "";
      }
      if(!this.$u.test.isEmpty(this.dataForm.busiCountyCode)){
        this.dataForm.busiAreaStr += commonService.getPersonLocal(this.dataForm.busiCountyCode, true).areaName || "";
      }
    }
    if (this.dataForm.personalPhoto) {
      this.personImagesList = [{
        gfiId: this.dataForm.personalPhoto,
      },];
    }
  },
  computed: {
    dataForm() {
      if(this.partyType == PARTY_TYPE_CODE.personal){
        return this.dataFormPerson;
      }else if(this.partyType == PARTY_TYPE_CODE.business || this.partyType == PARTY_TYPE_CODE.other){
        return this.dataFormBusOther;
      }
      return this.dataFormPerson;
    },
    uFormRef(){
      let u_form = this.$refs.uFormPerson;
      if(this.partyType == PARTY_TYPE_CODE.personal){
        u_form = this.$refs.uFormPerson;
      }else if(this.partyType == PARTY_TYPE_CODE.business || this.partyType == PARTY_TYPE_CODE.other){
        u_form = this.$refs.uFormBusOther;
      }
      return u_form;
    },
  },
  mounted() {
    if (!this.$u.test.isEmpty(this.dataForm.partyUuid)) {
      caseService.getPartyExtList(this.dataForm.partyUuid).then(res => {
        if (!res.success) return;
        this.partyExList = [...res.data,];
        this.partyExList.forEach(itm => {
          itm.id = uuidv4();
        });
      });
    }

  },
  methods: {
    changeDateCb(e) {
      console.log("===" + JSON.stringify(e));
      this.dataForm.birthday = e.year + '-' + e.month + '-' + e.day;
    },
    // 数据字典组件选择事件
    dicSelectOpen: function(keyWord) {
      if (this.dicKeyWords == keyWord && this.dicShow) {
        return true;
      }
      return false;
    },
    getDicName(code) {
      return this.$u.dic.getDicNameByKeyCode(this.$u.dic.DIC_KEYS.INFO_TYPE, code);
    },
    showDic: function(key, cur) {
      if (this.dicShow) return;
      this.dicKeyWords = key;
      this.dicCurrentSelect = cur;
      this.dicShow = true;
    },
    // 涉案人
    searchEnterPerson(txt){
      let params = {
        page:1,
        limit:10,
        licNo:txt,
      }
      return new Promise((resolve, reject) => {
        caseService.likeLicCom(params).then(res => {
          if(res.success){
            let tmp  = res.data;
            tmp.forEach(itm => {
              itm.name = itm.managerName + '   ' + itm.licNo;
              itm.partyName = itm.managerName;
              itm.id = itm.retailerUuid;
            });
            resolve(tmp);
          }else{
            resolve([]);
          }
        }).catch(err => {
          resolve([]);
        });
      });
    },
    searchEnterprise(txt){
      let params = {
        page:1,
        limit:10,
        licNo:txt,
      }
      return new Promise((resolve, reject) => {
        caseService.likeLicCom(params).then(res => {
          if(res.success){
            let tmp  = res.data;
            tmp.forEach(itm => {
              itm.name = [itm.companyName,].join("");
              itm.id = itm.retailerUuid;
            });
            resolve(tmp);
          }else{
            resolve([]);
          }
        }).catch(err => {
          resolve([]);
        });
      });
    },
    selectDicConfirm: function(e) {
      // 类型
      if (this.dicKeyWords == this.$u.dic.DIC_KEYS.ROLE_OF_CASE) {
        this.dataForm.roleOfCaseStr = e[0].label;
        this.dataForm.roleOfCase = e[0].extra.bcbCode;
      } else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.C_PARTYINFO_TYPE) {
        this.dataForm.partakeRoleStr = e[0].label;
        this.dataForm.partakeRole = e[0].extra.bcbCode;
      } else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.BSC_GENDDER) {
        this.dataForm.partySexStr = e[0].label;
        this.dataForm.partySex = e[0].extra.bcbCode;
      } else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.IDCARD_TYPE) {
        this.dataForm.idCardTypeStr = e[0].label;
        this.dataForm.idCardType = e[0].extra.bcbCode;
      } else if (this.dicKeyWords == this.$u.dic.DIC_KEYS.NATION_LIST) {
        this.dataForm.nationStr = e[0].label;
        this.dataForm.nation = e[0].extra.bcbCode;
      }
    },
    addExtInfo() {
      this.choiceExtItem = undefined;
      this.extInfoShow = true;
    },
    extClick(index, index1) {
      if (index1 === 1) {
        this.partyExList.splice(index, 1);
        this.$forceUpdate();
      } else {
        this.partyExList[index].show = false;
        this.choiceExtItem = this.partyExList[index];
        this.extInfoShow = true;
      }
      this.partyExList.map(item => {
        item.show = false;
      });
    },
    infoSelect () {
      this.$u.route("pages/case/caseInfoTemp/partyList?busiLicNo=" + this.dataFormBusOther.busiLiceNo)
    },
    updateBackState (param) {
      // this.$refs['mescrollItem0'].refresh();
      this.$set(this.dataForm, 'picPerson', param.refresh[0].picPerson);
      this.$set(this.dataForm, 'idCardType', param.refresh[0].idCardType);
      this.$set(this.dataForm, 'picIdCard', param.refresh[0].picIdCard);
      this.$set(this.dataForm, 'partySex', param.refresh[0].partySex);
      this.$set(this.dataForm, 'nation', param.refresh[0].nation);
      let nation  = this.$u.dic.getDicNameByKeyCode(this.$u.dic.DIC_KEYS.NATION_LIST, param.refresh[0].nation)
      let idCardType  = this.$u.dic.getDicNameByKeyCode(this.$u.dic.DIC_KEYS.IDCARD_TYPE, param.refresh[0].idCardType)
      let partySex  = this.$u.dic.getDicNameByKeyCode(this.$u.dic.DIC_KEYS.BSC_GENDDER, param.refresh[0].partySex)
      this.$set(this.dataForm, 'idCardTypeStr', idCardType);
      this.$set(this.dataForm, 'partySexStr', partySex);
      this.$set(this.dataForm, 'nationStr', nation);
      let age = getGenderByIdNumber(param.refresh[0].picIdCard).age
      this.$set(this.dataForm, 'age', age);
      this.uFormRef.validate(valid => { })
    },
    extOpen(index) {
      this.partyExList[index].show = true;
      this.partyExList.map((val, idx) => {
        if (index != idx) this.partyExList[idx].show = false;
      });
    },
    confirmExtItem(e) {
      let pos = -1;
      for (let i = 0; i < this.partyExList.length; i++) {
        if (this.partyExList[i].id == e.id) {
          pos = i;
          break;
        }
      }
      if (pos != -1) {
        this.partyExList[pos] = e;
      } else {
        this.$set(e, 'show', false);
        e.id = uuidv4();
        this.partyExList.push(e);
      }
      this.extInfoShow = false;
    },
    getImgs(e, pos) {
      if (pos == '1') {
        this.personImagesList = [...e,];
      }
    },
    radioGroupChange(e) {
      this.dataForm.partyType = e;
      this.partyType = e;
      if(this.partyType != PARTY_TYPE_CODE.personal){
        this.$refs.uFormBusOther.setRules(this.busOtherRules);
      }else{
        this.$refs.uFormPerson.setRules(this.personRules);
      }
    },
    searchData(txt) {
      return new Promise((resolve, reject) => {
        // 身份证 或 临时身份证
        if(this.dataForm.idCardType == IDCARD_TYPE_CODE.IDENTIFICATION || this.dataForm.idCardType == IDCARD_TYPE_CODE.TEMID){
          if (!this.$u.test.idCard(txt)) {
            resolve([]);
            return;
          }
          caseService.getPartyInfoByNo(txt).then(res => {
            if (res.data) {
              res.data.forEach(itm => {
                if(itm.partyType != PARTY_TYPE_CODE.personal){
                  itm.id = itm.picIdCard;
                  itm.name = itm.picPerson + ',' + itm.busiLiceNo;
                }else{
                  itm.id = txt;
                  itm.name = (this.$u.test.isEmpty(itm.partyName) ? itm.companyName : itm.partyName) + ',' + itm.busiLiceNo;
                }
              });
            }
            resolve(res.data);
          }).catch(er => {
            resolve([]);
          });
        }else if(this.dataForm.idCardTypeStr == '许可证'){
          caseService.likeLicNo({
            page: 1,
            limit: 1,
            licNo: txt,
          }).then(res => {
            if(res.success && res.data && res.data.length > 0){
              res.data.forEach(itm => {
                itm.partyType = this.partyType;
                if(this.partyType != PARTY_TYPE_CODE.personal){
                  itm.id = itm.licNo;
                  itm.name = itm.managerName + ',' + itm.businessLicNo;
                }else{
                  itm.id = txt;
                  itm.name = (this.$u.test.isEmpty(itm.managerName) ? itm.companyName : itm.managerName) + ',' + itm.businessLicNo;
                }
                itm.partyName = itm.managerName;
                itm.picPerson =  itm.managerName;
                itm.busiLiceNo = itm.businessLicNo;
                itm.phone = itm.retailTel;
                itm.busiAddr = itm.businessAddr;
                itm.idCardAddr = itm.managerCredAddr;
              });
              resolve(res.data);
            }else{
              this.$u.toast('无数据');
              resolve([]);
            }
          }).catch(err => {
            this.$u.toast('查询失败');
            resolve([]);
          });
        }else {
          resolve([]);
          return;
        }

      });
    },
    choiceAutoItem(itm, index) {
      if (index == '1') { // 个人身份证
        if (itm.partyType != PARTY_TYPE_CODE.personal) {
          this.$set(this.dataForm, 'partyName', itm.companyName);
          this.$set(this.dataForm, 'busiLiceNo', itm.busiLiceNo);
          this.$set(this.dataForm, 'picPerson', itm.picPerson);
          this.$set(this.dataForm, 'picPhone', itm.phone);
          this.$set(this.dataForm, 'busiAddr', itm.busiAddr);
        } else {
          this.$set(this.dataForm, 'partyName', this.$u.test.isEmpty(itm.partyName) ? itm.companyName : itm.partyName);
          this.$set(this.dataForm, 'busiLiceNo', itm.busiLiceNo);
          // this.$set(this.dataForm,'picPerson', itm.picPerson);
          this.$set(this.dataForm, 'phone', itm.phone);
          this.$set(this.dataForm, 'busiAddr', itm.busiAddr);
          this.$set(this.dataForm, 'partySex', itm.partySex);
          this.$set(this.dataForm, 'idCardAddr', itm.idCardAddr);
          this.$set(this.dataForm, 'personalBusiAddr', itm.personalBusiAddr);
        }
      } else if (index == '2') { // 法人/其他组织 身份证
        if (itm.partyType != PARTY_TYPE_CODE.personal) {
          this.$set(this.dataForm, 'picPerson', itm.picPerson);
          this.$set(this.dataForm, 'companyName', itm.companyName);
          this.$set(this.dataForm, 'busiLiceNo', itm.busiLiceNo);
          this.$set(this.dataForm, 'partySex', itm.partySex);
          this.$set(this.dataForm, 'idCardAddr', itm.idCardAddr);
          this.$set(this.dataForm, 'phone', itm.phone);
          this.$set(this.dataForm, 'personalBusiAddr', itm.busiAddr);
          this.$set(this.dataForm, 'busiAddr', itm.busiAddr);
        } else {
          this.$set(this.dataForm, 'picPerson', itm.partyName);
          this.$set(this.dataForm, 'companyName', itm.companyName);
          this.$set(this.dataForm, 'busiLiceNo', itm.busiLiceNo);
          this.$set(this.dataForm, 'partySex', itm.partySex);
          this.$set(this.dataForm, 'idCardAddr', itm.idCardAddr);
          this.$set(this.dataForm, 'phone', itm.phone);
          this.$set(this.dataForm, 'personalBusiAddr', itm.busiAddr);
        }
      } else if (index == '3') { // 涉案企业查
        this.$set(this.dataForm, 'partyName', itm.name);
        this.$set(this.dataForm, 'busiLiceNo', itm.businessLicNo);
        this.$set(this.dataForm, 'picIdCard', itm.managerCredNum);
        this.$set(this.dataForm, 'idCardTypeStr', itm.managerCredTypeNm);
        this.$set(this.dataForm, 'idCardType', itm.managerCredType);
        this.$set(this.dataForm, 'picPerson', itm.managerName);
        this.$set(this.dataForm, 'busiAddr', itm.businessAddr);
        this.$set(this.dataForm, 'phone', itm.retailTel);
        this.$set(this.dataForm, 'picPhone', itm.contactMobile);
        this.$set(this.dataForm, 'idCardAddr', itm.managerCredAddr);
        if (getGenderByIdNumber(itm.managerCredNum).sex == '0') {
          this.$set(this.dataForm, 'partySex', GENDER_TYPE.FEMALE);
          this.$set(this.dataForm, 'partySexStr', '女性');
        } else {
          this.$set(this.dataForm, 'partySex', GENDER_TYPE.MALE);
          this.$set(this.dataForm, 'partySexStr', '男性');
        }
        let age = getGenderByIdNumber(itm.managerCredNum).age
        this.$set(this.dataForm, 'age', age);
      } else if (index == '4') { // 涉案人查
        this.$set(this.dataForm, 'partyName', itm.partyName);
        this.$set(this.dataForm, 'busiLiceNo', itm.businessLicNo);
        this.$set(this.dataForm, 'idCard', itm.managerCredNum);
        this.$set(this.dataForm, 'idCardTypeStr', itm.managerCredTypeNm);
        this.$set(this.dataForm, 'idCardType', itm.managerCredType);
        this.$set(this.dataForm, 'picPerson', itm.managerName);
        this.$set(this.dataForm, 'busiAddr', itm.managerLocal);
        this.$set(this.dataForm, 'personalBusiAddr', itm.businessAddr);
        this.$set(this.dataForm, 'phone', itm.retailTel);
        this.$set(this.dataForm, 'idCardAddr', itm.managerCredAddr);
        this.$set(this.dataForm, 'companyName', itm.companyName);
        this.$set(this.dataForm, 'partyPostcode', itm.postcode);
        if (getGenderByIdNumber(itm.managerCredNum).sex == '0') {
          this.$set(this.dataForm, 'partySex', GENDER_TYPE.FEMALE);
          this.$set(this.dataForm, 'partySexStr', '女性');
        } else {
          this.$set(this.dataForm, 'partySex', GENDER_TYPE.MALE);
          this.$set(this.dataForm, 'partySexStr', '男性');
        }
        let age = getGenderByIdNumber(itm.managerCredNum).age
        this.$set(this.dataForm, 'age', age);
        let birthday = getGenderByIdNumber(itm.managerCredNum).birthday
        this.$set(this.dataForm, 'birthday', birthday);
      }
      console.log(this.dataFormPerson.busiLiceNo)
      let pos = -1;
      console.log(this.partyExList)
      for (let i = 0; i < this.partyExList.length; i++) {
        if (this.partyExList[i].infoContent == itm.licNo && this.partyExList[i].infoType == C_INFO_TYPE.LIC_NO) {
          pos = i;
          break;
        }
      }
      if (pos == -1) {
        let extItm = {
          infoType: C_INFO_TYPE.LIC_NO,
          infoTypeStr:"零售许可证号",
          infoItem:itm.companyName || "零售许可证号",
          infoContent:itm.licNo,
          id:uuidv4(),
        };
        this.partyExList[pos] = extItm;
        this.partyExList = [];
        this.partyExList.push(extItm);
      }
      this.uFormRef.validate(valid => { })
    },
    save() {
      this.uFormRef.validate(valid => {
        if (!valid) return;
        this.$modal.showLoading('正在保存...');
        // TODO 数据
        this.dataForm.partyType = this.partyType;
        this.dataForm.caseUuid = this.caseUuid;
        this.dataForm.partyUuid = this.$u.test.isEmpty(this.partyUuid) ? "" : this.partyUuid;
        if(this.personImagesList && this.personImagesList.length > 0){
          this.dataForm.personalPhoto = this.personImagesList[0].gfiId;
        }else{
          this.dataForm.personalPhoto = "";
        }
        this.dataForm.partyExList = this.partyExList;
        caseService.savePartyInfo(this.dataForm).then(res => {
          this.$modal.hideLoading();
          if (res.success) {
            this.backPrev({
              paramKey: "partyBack",
              param: true,
            });
          } else {
            this.$modal.alert("保存失败:" + res.msg);
          }
        }).catch(err => {
          this.$modal.hideLoading();
          this.$modal.alert('保存失败:' + err);
        });
      });
    },
    showArea(type){
      this.areaType = type;
      this.areaShow = true;
    },
    nativeNameSelectShowComfir(areas) {
      let str = "";
      if(this.$modal.isMuniCity(areas[0].proCode)){
        str = [areas[0].admdivName, areas[0].countryName,].join("");
      }else{
        str = [areas[0].proName, areas[0].admdivName, areas[0].countryName,].join("");
      }
      if(this.areaType == 1){ // 籍贯
        this.dataForm.nativeAreaStr = str;
        this.dataForm.nativeProvCode = areas[0].proCode;
        this.dataForm.nativeCityCode = areas[0].admdivCode;
        this.dataForm.nativeCountyCode = areas[0].countryCode;
      }else{ // 经营地址
        this.dataForm.busiAreaStr = str;
        this.dataForm.busiProvCode = areas[0].proCode;
        this.dataForm.busiCityCode = areas[0].admdivCode;
        this.dataForm.busiCountyCode = areas[0].countryCode;
      }
      this.areaShow = false;
    },
    scanLicCode() {
      // #ifdef H5-DINGDING || H5-WECHAT || H5-EMP
      this.$deviceApi.scan().then(res => {
        let licNo =  res.replace(/ +/g,"").replace(/[\r\n]/g,"");
        try{
          let start = licNo.indexOf('许可证号') + 5;
          let num = licNo.indexOf('发证机关') - start;
          licNo = licNo.substr(start, num);
        }catch(e){
          console.log(e);
        }
        if(!this.$u.test.digits(licNo)){
          this.$u.toast('解析失败');
          return;
        }
        caseService.likeLicNo({
          page: 1,
          limit: 1,
          licNo: licNo,
        }).then(res => {
          if(res.success && res.data && res.data.length > 0){
            let itm = res.data[0];
            if (this.dataForm.partyType != PARTY_TYPE_CODE.personal) { // 法人身份证
              this.$set(this.dataForm,'partyName', itm.companyName);
              this.$set(this.dataForm,'busiLiceNo', itm.businessLicNo);
              this.$set(this.dataForm,'picPerson', itm.managerName);
              this.$set(this.dataForm,'picPhone', itm.retailTel);
              this.$set(this.dataForm,'busiAddr', itm.businessAddr);
              this.$set(this.dataForm,'idCardType', itm.managerCredType);
              this.$set(this.dataForm,'picIdCard', itm.managerCredNum);
            } else { // 身份证
              this.$set(this.dataForm,'companyName', itm.companyName);
              this.$set(this.dataForm,'partyName', itm.managerName);
              this.$set(this.dataForm,'busiLiceNo', itm.businessLicNo);
              this.$set(this.dataForm,'partySex', itm.managerGender);
              this.$set(this.dataForm,'idCardAddr', itm.managerCredAddr);
              this.$set(this.dataForm,'phone', itm.retailTel);
              this.$set(this.dataForm,'personalBusiAddr', itm.businessAddr);
              this.$set(this.dataForm,'idCardType', itm.managerCredType);
              this.$set(this.dataForm,'idCard', itm.managerCredNum);
            }
          }else{
            this.$u.toast('无数据');
          }
        }).catch(err => {
          this.$u.toast('查询失败');
        });
      }).catch(err => {
        this.$u.toast('扫描失败');
      });
      // #endif
    },
  },
}
</script>

<style lang="scss" scoped>
@import "../case_common.scss";
.page{ padding:0; }
.nav-right-icon {
	margin-right: 30rpx;
	font-size: .8rem;
	color: #FFF;
}

.content {
	.party-info-content {
		padding: 10px 16px 16px;

		.party-info-title {
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			align-items: center;

			.p-title-text {
				font-size: $font_size_1;
				font-weight: bold;
			}
		}

	}
}

.party-info-box {
	// margin: $cm-conent-padding-column 0;
	.text-right {
		text-align: right !important;
	}
}

.ext-lay {
	width: 100%;
	padding: 5rpx 16px;
}

.ext-lay-header {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	width: 100%;
	padding-bottom: 20rpx;
	border-bottom: 1rpx solid $u-border-color;
}

.ext-lay-header-title {
	color: black;
	font-size: 36rpx;
}

.ext-lay-content {
	display: flex;
	flex-direction: column;
	padding-bottom: 5rpx;
	border-bottom: 1rpx solid $u-border-color;
}

.ext-lay-content-title {
	font-size: 26rpx;
	color: black;
	margin-bottom: 5rpx;
	margin-top: 10rpx;
}

.ext-lay-content-sub {
	font-size: 20rpx;
	color: #565656;
	margin: 5rpx 0;
}
</style>
